{  Statement: http://acmp.ru/?main=task&id_task=79
   Verdict: Accepted
}
uses
        SysUtils, Math;

var
    a,b,ans,i:longint;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(a,b);
ans := a mod 10;
for i := 2 to b do
    ans := ans * a mod 10;
write(ans);
end.